import {
  get,
  post,
  put,
  del,
} from "./base_service"


/**
 * 所有团队相关
 *
 * allen  2021-08-24
 */


/**
 * 获取业绩列表
 * @param {*} settlementStatus 
 */
const getMyPerformanceList = (settlementStatus) => {
  return new Promise((resolve, reject) => {
    get("/performance/list?settlementStatus=" + settlementStatus).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取个人业绩详情
 * @param {*} settlementId 
 */
const getMyPerformanceDetail = (settlementId) => {
  return new Promise((resolve, reject) => {
    get("/performance/detail?settlementId=" + settlementId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取个人业绩详情
 * @param {*} settlementId 
 */
const getPerformanceRank = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/performance/sort?page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 公司邀请员工入驻
 * @param {*} data 
 */
const companyInviteEmployeeEnter = (data) => {
  return new Promise((resolve, reject) => {
    post("/join/invite/employee", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 待审核公司成员列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const companyCheckEmployeeList = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/join/company/check/employee/list?page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 是否通过审核公司员工
 * @param {*} employeeId 
 * @param {*} isPass 
 */
const companyCheckAction = (employeeId, isPass) => {
  return new Promise((resolve, reject) => {
    get("/join/company/check/employee?employeeId=" + employeeId + "&isPass=" + isPass).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 公司员工列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const companyEmployeeList = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/join/company/employee?page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 删除一个公司成员
 * @param {*} employeeId 
 */
const deleteCompanyEmployee = (employeeId) => {
  return new Promise((resolve, reject) => {
    del("/join/company/delete/employee?employeeId=" + employeeId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 我的下级列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const myNextTeamList = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/user/next/Team?page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取公司对应房源员工驻场情况
 * @param {*} page 
 * @param {*} pageSize 
 */
const queryCompanyEmplyeeStation = (houseNumber, page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/expert/query/company/employee/resident?houseNumber=" + houseNumber + "&page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}







module.exports = {
  getMyPerformanceList,
  getMyPerformanceDetail,
  getPerformanceRank,
  companyInviteEmployeeEnter,
  companyCheckEmployeeList,
  companyEmployeeList,
  deleteCompanyEmployee,
  myNextTeamList,
  companyCheckAction,
  queryCompanyEmplyeeStation
}
